#pragma once

#include"LogIn.h"

namespace mpk_internal_system {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for LogInWindow
	/// </summary>
	public ref class LogInWindow : public System::Windows::Forms::Form
	{
	public:
		bool succeed_logged;
		sLogIn ^ logger;

		LogInWindow(void)
		{
			InitializeComponent();
			
			succeed_logged = false;

			logger = gcnew sLogIn();
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~LogInWindow()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  login;
	private: System::Windows::Forms::Label^  l_name;
	private: System::Windows::Forms::Label^  l_surname;
	private: System::Windows::Forms::TextBox^  textName;
	private: System::Windows::Forms::TextBox^  textSurname;


	private: System::Windows::Forms::Label^  l_pswd;
	private: System::Windows::Forms::TextBox^  textPSWD;

	private: System::Windows::Forms::GroupBox^  groupBox1;
	private: System::Windows::Forms::RadioButton^  radioAdmin;
	private: System::Windows::Forms::RadioButton^  radioEmployee;
	private: System::Windows::Forms::RadioButton^  radioUser;
	protected: 

	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->login = (gcnew System::Windows::Forms::Button());
			this->l_name = (gcnew System::Windows::Forms::Label());
			this->l_surname = (gcnew System::Windows::Forms::Label());
			this->textName = (gcnew System::Windows::Forms::TextBox());
			this->textSurname = (gcnew System::Windows::Forms::TextBox());
			this->l_pswd = (gcnew System::Windows::Forms::Label());
			this->textPSWD = (gcnew System::Windows::Forms::TextBox());
			this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
			this->radioAdmin = (gcnew System::Windows::Forms::RadioButton());
			this->radioEmployee = (gcnew System::Windows::Forms::RadioButton());
			this->radioUser = (gcnew System::Windows::Forms::RadioButton());
			this->groupBox1->SuspendLayout();
			this->SuspendLayout();
			// 
			// login
			// 
			this->login->Location = System::Drawing::Point(197, 227);
			this->login->Name = L"login";
			this->login->Size = System::Drawing::Size(75, 23);
			this->login->TabIndex = 0;
			this->login->Text = L"Login";
			this->login->UseVisualStyleBackColor = true;
			this->login->Click += gcnew System::EventHandler(this, &LogInWindow::login_Click);
			// 
			// l_name
			// 
			this->l_name->AutoSize = true;
			this->l_name->Location = System::Drawing::Point(78, 125);
			this->l_name->Name = L"l_name";
			this->l_name->Size = System::Drawing::Size(35, 13);
			this->l_name->TabIndex = 1;
			this->l_name->Text = L"Name";
			// 
			// l_surname
			// 
			this->l_surname->AutoSize = true;
			this->l_surname->Location = System::Drawing::Point(64, 157);
			this->l_surname->Name = L"l_surname";
			this->l_surname->Size = System::Drawing::Size(49, 13);
			this->l_surname->TabIndex = 2;
			this->l_surname->Text = L"Surname";
			// 
			// textName
			// 
			this->textName->Location = System::Drawing::Point(119, 122);
			this->textName->Name = L"textName";
			this->textName->Size = System::Drawing::Size(100, 20);
			this->textName->TabIndex = 3;
			// 
			// textSurname
			// 
			this->textSurname->Location = System::Drawing::Point(119, 154);
			this->textSurname->Name = L"textSurname";
			this->textSurname->Size = System::Drawing::Size(100, 20);
			this->textSurname->TabIndex = 4;
			// 
			// l_pswd
			// 
			this->l_pswd->AutoSize = true;
			this->l_pswd->Location = System::Drawing::Point(64, 191);
			this->l_pswd->Name = L"l_pswd";
			this->l_pswd->Size = System::Drawing::Size(53, 13);
			this->l_pswd->TabIndex = 5;
			this->l_pswd->Text = L"Password";
			// 
			// textPSWD
			// 
			this->textPSWD->Location = System::Drawing::Point(119, 188);
			this->textPSWD->Name = L"textPSWD";
			this->textPSWD->PasswordChar = '*';
			this->textPSWD->Size = System::Drawing::Size(100, 20);
			this->textPSWD->TabIndex = 6;
			// 
			// groupBox1
			// 
			this->groupBox1->Controls->Add(this->radioAdmin);
			this->groupBox1->Controls->Add(this->radioEmployee);
			this->groupBox1->Controls->Add(this->radioUser);
			this->groupBox1->Location = System::Drawing::Point(67, 12);
			this->groupBox1->Name = L"groupBox1";
			this->groupBox1->Size = System::Drawing::Size(152, 100);
			this->groupBox1->TabIndex = 7;
			this->groupBox1->TabStop = false;
			this->groupBox1->Text = L"Who you are\?";
			// 
			// radioAdmin
			// 
			this->radioAdmin->AutoSize = true;
			this->radioAdmin->Location = System::Drawing::Point(14, 65);
			this->radioAdmin->Name = L"radioAdmin";
			this->radioAdmin->Size = System::Drawing::Size(54, 17);
			this->radioAdmin->TabIndex = 2;
			this->radioAdmin->TabStop = true;
			this->radioAdmin->Text = L"Admin";
			this->radioAdmin->UseVisualStyleBackColor = true;
			this->radioAdmin->CheckedChanged += gcnew System::EventHandler(this, &LogInWindow::radioAdmin_CheckedChanged);
			// 
			// radioEmployee
			// 
			this->radioEmployee->AutoSize = true;
			this->radioEmployee->Location = System::Drawing::Point(14, 42);
			this->radioEmployee->Name = L"radioEmployee";
			this->radioEmployee->Size = System::Drawing::Size(71, 17);
			this->radioEmployee->TabIndex = 1;
			this->radioEmployee->TabStop = true;
			this->radioEmployee->Text = L"Employee";
			this->radioEmployee->UseVisualStyleBackColor = true;
			this->radioEmployee->CheckedChanged += gcnew System::EventHandler(this, &LogInWindow::radioEmployee_CheckedChanged);
			// 
			// radioUser
			// 
			this->radioUser->AutoSize = true;
			this->radioUser->Location = System::Drawing::Point(14, 19);
			this->radioUser->Name = L"radioUser";
			this->radioUser->Size = System::Drawing::Size(81, 17);
			this->radioUser->TabIndex = 0;
			this->radioUser->TabStop = true;
			this->radioUser->Text = L"Simple User";
			this->radioUser->UseVisualStyleBackColor = true;
			this->radioUser->CheckedChanged += gcnew System::EventHandler(this, &LogInWindow::radioUser_CheckedChanged);
			// 
			// LogInWindow
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(284, 262);
			this->Controls->Add(this->groupBox1);
			this->Controls->Add(this->textPSWD);
			this->Controls->Add(this->l_pswd);
			this->Controls->Add(this->textSurname);
			this->Controls->Add(this->textName);
			this->Controls->Add(this->l_surname);
			this->Controls->Add(this->l_name);
			this->Controls->Add(this->login);
			this->Name = L"LogInWindow";
			this->ShowInTaskbar = false;
			this->Text = L"LogInWindow";
			this->Load += gcnew System::EventHandler(this, &LogInWindow::LogInWindow_Load);
			this->groupBox1->ResumeLayout(false);
			this->groupBox1->PerformLayout();
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	public: System::Void login_Click(System::Object^  sender, System::EventArgs^  e) {
				if(radioAdmin->Checked){
					if(logger->check_pswd_admin(textPSWD->Text->ToString())){
						logger->user = "admin";

						succeed_logged = true;
					}
					
					textName->Enabled = false;
					textSurname->Enabled = false;
					textPSWD->Enabled = true;

					MessageBox::Show("Invalid password!");
				}
				else if(radioEmployee->Checked){
					if(logger->check_pswd_employee(textName->Text->ToString(), 
						textSurname->Text->ToString(), textPSWD->Text->ToString())){
							logger->user = "employee";

							succeed_logged = true;
					}

					textName->Enabled = true;
					textSurname->Enabled = true;
					textPSWD->Enabled = true;

					MessageBox::Show("Invalid name, surname or password!");
				}
				else if(radioUser->Checked){
					logger->user = "user";
					succeed_logged = true;
				}
			 }
	private: System::Void LogInWindow_Load(System::Object^  sender, System::EventArgs^  e) {
				 radioUser->Checked = true;
				 textName->Enabled = false;
				 textSurname->Enabled = false;
				 textPSWD->Enabled = false;
			 }
	private: System::Void radioAdmin_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
				 textName->Enabled = false;
				textSurname->Enabled = false;
				textPSWD->Enabled = true;
			 }
	private: System::Void radioEmployee_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
				 textName->Enabled = true;
				textSurname->Enabled = true;
				textPSWD->Enabled = true;
			 }
	private: System::Void radioUser_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
				textName->Enabled = false;
				textSurname->Enabled = false;
				textPSWD->Enabled = false;
			 }
};
}